/**
 * Created by asus on 2017/5/5.
 */
const faker = require('faker')
const lib = require('lodash')
faker.locale = 'zh_CN'

module.exports = {
  api: '/codi-admin-mock/sys/affiche',
  response: function (req, res) {
    console.log(req.method)
    if (req.method === 'GET') {
      console.log(req.query)
      let index = parseInt(req.query.page)
      let size = parseInt(req.query.size)
      const total = 36
      const page = Math.ceil(total / size)
      let resNum = index >= page ? (total - (index - 1) * size) : size
      let data = {
        'success': true,
        'objs': lib.times(resNum, function (n) {
          var data = {
            'endTime': 1493778376087,
            'id': n + ((index - 1) * size),
            'isUp': (n % 2 === 1) ? true : false,
            'location': (n % 2 === 1) ? 'PC' : 'APP',
            'publishTime': 1493777771287,
            'publisher': 'admin',
            'title': '测试数据有内容' + (n + ((index - 1) * size))
          }
          n % 2 === 1 ? (data.content = '测试内容') : (data.link = 'http://baidu.com')
          return data
        }),
        'page': index,
        'rowCount': resNum,
        'size': resNum,
        'totalNum': total,
        'totalPage': page
      }
      res.json(data)
    } else if (req.method === 'POST') {
      console.log(req.query)
      res.json({
        'success': true,
        'result': {
          'content': '测试内容',
          'endTime': 1493795802970,
          'id': 1,
          'location': 'PC',
          'publishTime': 1493795198170,
          'publisher': 'admin',
          'title': '测试数据有内容',
          'up': true
        }
      })
    }
  }
}
